/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on 14-sep-2011, 12:27:55
 */
package GUI;

import Euclidian.Euclidian;
import Filters.FrequencyFilter;
import Filters.Kalman3;
import Filters.MWA;
import Test.BSSTest;
import Transformers.BSS;
import Transformers.BaselineWonder;
import Transformers.Fourier;
import Transformers.QRSDet;
import Transformers.TimeSeries;
import Transformers.Wavelets.DaubechieWavelet;
import Transformers.Wavelets.HaarWavelet;
import java.awt.Dimension;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import org.jfree.chart.ChartPanel;

/**
 *
 * @author Cliff
 */
public class GUI extends javax.swing.JFrame {

    private File currentFile;
    private double [][] results = new double[6][17];
    /** Creates new form GUI */
    public GUI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        sampleSizeField = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        chartPanel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        fourierPanel = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        haarPanel = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        daubechiesPanel = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        kalmanPanel = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        bssPanel = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        QRSBSSPanel = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        sineChartPanel = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton14 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ECG Analysis");
        setMinimumSize(new java.awt.Dimension(1024, 700));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Source Selection"));

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Thorax 1");

        jCheckBox2.setSelected(true);
        jCheckBox2.setText("Thorax 2");

        jCheckBox3.setSelected(true);
        jCheckBox3.setText("Abdomen 1");

        jCheckBox4.setSelected(true);
        jCheckBox4.setText("Abdomen 2");

        jCheckBox5.setSelected(true);
        jCheckBox5.setText("Abdomen 3");

        jButton1.setText("Update");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setText("Sample Size:");

        sampleSizeField.setText("1000");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sampleSizeField, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox3)
                    .addComponent(jCheckBox4)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox4))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sampleSizeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox5)
                    .addComponent(jButton1))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        chartPanel.setLayout(new javax.swing.BoxLayout(chartPanel, javax.swing.BoxLayout.PAGE_AXIS));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Original", jPanel2);

        fourierPanel.setLayout(new javax.swing.BoxLayout(fourierPanel, javax.swing.BoxLayout.PAGE_AXIS));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fourierPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fourierPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Fourier", jPanel4);

        haarPanel.setLayout(new javax.swing.BoxLayout(haarPanel, javax.swing.BoxLayout.PAGE_AXIS));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(haarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(haarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Haar Wavelet", jPanel5);

        daubechiesPanel.setLayout(new javax.swing.BoxLayout(daubechiesPanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(daubechiesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(daubechiesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Daubechies", jPanel7);

        kalmanPanel.setLayout(new javax.swing.BoxLayout(kalmanPanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(kalmanPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(kalmanPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Adapt. Kalman", jPanel8);

        bssPanel.setLayout(new javax.swing.BoxLayout(bssPanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1004, Short.MAX_VALUE)
            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel9Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(bssPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 463, Short.MAX_VALUE)
            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel9Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(bssPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        jTabbedPane1.addTab("BSS", jPanel9);

        QRSBSSPanel.setLayout(new javax.swing.BoxLayout(QRSBSSPanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1004, Short.MAX_VALUE)
            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel10Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(QRSBSSPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 463, Short.MAX_VALUE)
            .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel10Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(QRSBSSPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        jTabbedPane1.addTab("QRS - BSS", jPanel10);

        sineChartPanel.setLayout(new javax.swing.BoxLayout(sineChartPanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(sineChartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(sineChartPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Sine", jPanel11);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Calculate"));

        jButton2.setText("Fourier");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Haar Wavelet");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton9.setText("Daubechies");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setText("BSS");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setText("QRS - BSS");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setText("QRS2");

        jButton13.setText("Sine");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "BSS", "MWA", "MWM", "MWG", "AKF", "Original Sine" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jList1);

        jButton14.setText("Test");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                .addComponent(jButton14)
                .addContainerGap())
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton10, jButton11, jButton2, jButton3, jButton9});

        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton14)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2)
                            .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3)
                            .addComponent(jButton12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton9)
                            .addComponent(jButton13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10)))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter"));

        jButton4.setText("MWA - Normal");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("MWA - Median");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("MWA - Gaussian");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Band Pass Filter");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Adpt. Kalman");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton8)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton4, jButton5, jButton6, jButton7, jButton8});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Open file..");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        jMenuItem2.setText("Exit");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        String userDir = System.getProperty("user.dir");
        JFileChooser fileChooser = new JFileChooser(userDir);
        int rc = fileChooser.showDialog(null, "Select Data File");
        if (rc == JFileChooser.APPROVE_OPTION) {
            currentFile = fileChooser.getSelectedFile();
            Buffer.readFile(fileChooser.getSelectedFile(), Integer.parseInt(sampleSizeField.getText()));
            drawOriginalGraph(getFilterData(Buffer.getCurrentSampleSize()));
        }

    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        chartPanel.removeAll();
        drawOriginalGraph(getFilterData(Integer.parseInt(sampleSizeField.getText())));
        chartPanel.revalidate();
        chartPanel.repaint();

        /*fourierPanel.removeAll();
        drawFourierGraph(getFilterData(Buffer.getCurrentSampleSize()));
        fourierPanel.revalidate();
        fourierPanel.repaint();
        
        haarPanel.removeAll();
        drawHaarGraph(getFilterData(Buffer.getCurrentSampleSize()));
        haarPanel.revalidate();
        haarPanel.repaint();*/
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        fourierPanel.removeAll();
        drawFourierGraph(getFilterData(Buffer.getCurrentSampleSize()));
        fourierPanel.revalidate();
        fourierPanel.repaint();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        haarPanel.removeAll();
        drawHaarGraph(getFilterData(Buffer.getCurrentSampleSize()));
        haarPanel.revalidate();
        haarPanel.repaint();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        double[][] originalData = getFilterData(Buffer.getCurrentSampleSize());
        int left = Integer.parseInt(JOptionPane.showInputDialog("Left window size: "));
        int right = Integer.parseInt(JOptionPane.showInputDialog("Right window size: "));
        double[][] filteredData = new double[5][MWA.resultSize(Buffer.getCurrentSampleSize(), left, right)];

        for (int i = 0; i < 5; i++) {
            filteredData[i] = MWA.normal(originalData[i], left, right);
        }

        chartPanel.removeAll();
        drawOriginalGraph(filteredData);
        chartPanel.revalidate();
        chartPanel.repaint();

        fourierPanel.removeAll();
        drawFourierGraph(filteredData);
        fourierPanel.revalidate();
        fourierPanel.repaint();

        haarPanel.removeAll();
        drawHaarGraph(filteredData);
        haarPanel.revalidate();
        haarPanel.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        double[][] originalData = getFilterData(Buffer.getCurrentSampleSize());
        int left = Integer.parseInt(JOptionPane.showInputDialog("Left window size: "));
        int right = Integer.parseInt(JOptionPane.showInputDialog("Right window size: "));
        double[][] filteredData = new double[5][MWA.resultSize(Buffer.getCurrentSampleSize(), left, right)];

        for (int i = 0; i < 5; i++) {
            filteredData[i] = MWA.median(originalData[i], left, right);
        }

        chartPanel.removeAll();
        drawOriginalGraph(filteredData);
        chartPanel.revalidate();
        chartPanel.repaint();

        fourierPanel.removeAll();
        drawFourierGraph(filteredData);
        fourierPanel.revalidate();
        fourierPanel.repaint();

        haarPanel.removeAll();
        drawHaarGraph(filteredData);
        haarPanel.revalidate();
        haarPanel.repaint();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        double[][] originalData = getFilterData(Buffer.getCurrentSampleSize());
        int left = Integer.parseInt(JOptionPane.showInputDialog("Left window size: "));
        int right = Integer.parseInt(JOptionPane.showInputDialog("Right window size: "));
        double[][] filteredData = new double[5][MWA.resultSize(Buffer.getCurrentSampleSize(), left, right)];

        for (int i = 0; i < 5; i++) {
            filteredData[i] = MWA.gaussian(originalData[i], left, right);
        }

        chartPanel.removeAll();
        drawOriginalGraph(filteredData);
        chartPanel.revalidate();
        chartPanel.repaint();

        fourierPanel.removeAll();
        drawFourierGraph(filteredData);
        fourierPanel.revalidate();
        fourierPanel.repaint();

        haarPanel.removeAll();
        drawHaarGraph(filteredData);
        haarPanel.revalidate();
        haarPanel.repaint();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        int min = Integer.parseInt(JOptionPane.showInputDialog("Min frequency: "));
        int max = Integer.parseInt(JOptionPane.showInputDialog("Max frequency: "));
        double[][] originalData = getFilterData(Buffer.getCurrentSampleSize());

        double[][] filteredData = new double[5][Buffer.getCurrentSampleSize()];

        for (int i = 0; i < 5; i++) {
            filteredData[i] = FrequencyFilter.filterFrequency(originalData[i], min, max);
        }

        chartPanel.removeAll();
        drawOriginalGraph(filteredData);
        chartPanel.revalidate();
        chartPanel.repaint();

        fourierPanel.removeAll();
        drawFourierGraph(filteredData);
        fourierPanel.revalidate();
        fourierPanel.repaint();

        haarPanel.removeAll();
        drawHaarGraph(filteredData);
        haarPanel.revalidate();
        haarPanel.repaint();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        kalmanPanel.removeAll();
        drawKalmanGraph(getFilterData(Buffer.getCurrentSampleSize()));
        kalmanPanel.revalidate();
        kalmanPanel.repaint();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        daubechiesPanel.removeAll();
        drawDaubechiesGraph(getFilterData(Buffer.getCurrentSampleSize()));
        daubechiesPanel.revalidate();
        daubechiesPanel.repaint();
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        bssPanel.removeAll();
        drawBSSGraph(getFilterData(Buffer.getCurrentSampleSize()));
        bssPanel.revalidate();
        bssPanel.repaint();
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        double[][] data = getFilterData(Buffer.getCurrentSampleSize());
        BSS bss = new BSS();
        double[][] whiteData = bss.preWhiten(data);
        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        plotData = bss.BSS(whiteData, 50);

        QRSDet det = new QRSDet();
        double[] processed = det.preProcess(plotData[0]);
        det.initBuffers(plotData[0], processed);
        ArrayList<Integer> list = det.qrsDetection(plotData[0], processed);

        String[] dataLabel = {"BSS Result", "QRS Wavelet", "Marked QRS Peaks"};
        double[][] data2 = new double[3][1];
        //data2[0] = plotData[0];
        data2[0] = new double[Buffer.getCurrentSampleSize()];
        data2[0] = TimeSeries.center(data2[0]);
        data2[1] = processed;

        //data2[1] = TimeSeries.center(TimeSeries.scale(data2[1], 10000000));

        double[] marks = new double[Buffer.getCurrentSampleSize()];
        for (int i = 0; i < list.size(); i++) {
            //marks[list.get(i)] = plotData[0][list.get(i)];
            marks[i] =  det.getPeakTreshold();
        }

        data2[2] = marks;


        QRSBSSPanel.removeAll();
        ChartPanel panel = Plot.multipleChannelStandardPlot(data2, "QRS - BSS", dataLabel, "Sample", "mV");
        QRSBSSPanel.add(panel);
        QRSBSSPanel.revalidate();
        QRSBSSPanel.repaint();
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        //ask for the  in a.sin(x)
        double a = Double.parseDouble(JOptionPane.showInputDialog("Value for a in sine function: "));
        Euclidian euc = new Euclidian();
        
        double [][] source = this.getFilterData(Buffer.getCurrentSampleSize());
        double [][] source2 = euc.generateSignals(this.getFilterData(Buffer.getCurrentSampleSize()),a);
        
        String[] datalabel = new String[source2.length];
        for (int i = 0; i < datalabel.length; i++) {
            datalabel[i] = "lol";
        }
        BSS bss = new BSS();
        sineChartPanel.removeAll();
        
        if(jList1.getSelectedIndex() == 0) {
            double [][] sineSignal, originalSine;
            originalSine = bss.preWhiten(source);
            originalSine = bss.BSS(originalSine, 50);
            sineSignal = bss.preWhiten(source2);
            sineSignal = bss.BSS(sineSignal, 50);
            System.out.println("Average distance: " + euc.distance(originalSine, sineSignal));
            
            ChartPanel panel = Plot.multipleChannelStandardPlot(sineSignal, "SQDSQD", datalabel, "x", "y");
            sineChartPanel.add(panel);
        } else if(jList1.getSelectedIndex() == 1) {
            double [][] mwa = new double [source2.length][source2[0].length];
            double [][] originalMwa = new double [source.length][source[0].length];
            for (int i = 0; i < source2.length; i++) {
                originalMwa[i] = MWA.normal(source[i], 5, 5);
                mwa[i] = MWA.normal(source2[i], 5, 5);
            }
            originalMwa = bss.preWhiten(originalMwa);
            originalMwa = bss.BSS(originalMwa, 50);
            mwa = bss.preWhiten(mwa);
            mwa = bss.BSS(mwa, 50);
            System.out.println("Average distance: " + euc.distance(originalMwa, mwa));
            ChartPanel panel = Plot.multipleChannelStandardPlot(mwa, "SQDSQD", datalabel, "x", "y");
            sineChartPanel.add(panel);
        } else if(jList1.getSelectedIndex()==2) {
            double [][] originalMwm = new double [source.length][source[0].length];
            double [][] mwm = new double [source2.length][source2[0].length];
            for (int i = 0; i < source2.length; i++) {
                mwm[i] = MWA.median(source2[i], 5, 5);
                originalMwm[i] = MWA.median(source[i], 5, 5);
            }
            originalMwm = bss.preWhiten(originalMwm);
            originalMwm = bss.BSS(originalMwm, 50);
            mwm = bss.preWhiten(mwm);
            mwm = bss.BSS(mwm, 50);
            System.out.println("Average distance: " + euc.distance(originalMwm, mwm));
            ChartPanel panel = Plot.multipleChannelStandardPlot(mwm, "SQDSQD", datalabel, "x", "y");
            sineChartPanel.add(panel);
        } else if(jList1.getSelectedIndex()==3) {
            double [][] originalMwg = new double [source.length][source[0].length];
            double [][] mwg = new double [source2.length][source2[0].length];
            for (int i = 0; i < source2.length; i++) {
                mwg[i] = MWA.gaussian(source2[i], 5, 5);
                originalMwg[i] = MWA.gaussian(source[i], 5, 5);
            }
            originalMwg = bss.preWhiten(originalMwg);
            originalMwg = bss.BSS(originalMwg, 50);
            mwg = bss.preWhiten(mwg);
            mwg = bss.BSS(mwg, 50);
            System.out.println("Average distance: " + euc.distance(originalMwg, mwg));
            ChartPanel panel = Plot.multipleChannelStandardPlot(mwg, "SQDSQD", datalabel, "x", "y");
            sineChartPanel.add(panel);
        }else if(jList1.getSelectedIndex() == 4){
               
        }else if(jList1.getSelectedIndex() == 5){
            System.out.println("Average distance: " + euc.distance(source2, source));
            ChartPanel panel = Plot.multipleChannelStandardPlot(source2, "SQDSQD", datalabel, "x", "y");
            sineChartPanel.add(panel);
        }
        sineChartPanel.revalidate();
        sineChartPanel.repaint();
    }//GEN-LAST:event_jButton13ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        System.out.println("a=0.2 \ta=0.25 \ta=0.3 \ta=0.35 \ta=0.4 \ta=0.45 \ta=0.5 \ta=0.55 \ta=0.6 \ta=0.65 \ta=0.7 \ta=0.75 \ta=0.8 \ta=0.85 \ta=0.9 \ta=0.95 \ta=1");
        
        Euclidian euc = new Euclidian();
        for (int g = 0; g < 10; g++) {
        double [][] source = this.getFilterData(Buffer.getCurrentSampleSize());
        BSSTest bss = new BSSTest(source);
        for (int k = 0; k < 6; k++) {
            System.out.println("\n k:" + k + "\t");
            int teller =0;
            for (double a = 0.2; a <1.02; a=a+0.05) {
                double [][] source2 = euc.generateSignals(source,a);

                String[] datalabel = new String[source2.length];
                for (int i = 0; i < datalabel.length; i++) {
                    datalabel[i] = "lol";
                }
                //BSS bss = new BSS();
                sineChartPanel.removeAll();

                if(k == 0) {
                    double [][] sineSignal, originalSine;
                    originalSine = bss.preWhiten(source);
                    originalSine = bss.BSS(originalSine, 50);
                    sineSignal = bss.preWhiten(source2);
                    sineSignal = bss.BSS(sineSignal, 50);
                    results[k][teller] += euc.distance(originalSine, sineSignal);
                    System.out.print(euc.distance(originalSine, sineSignal) + "\t");
                } else if(k== 1) {
                    double [][] mwa = new double [source2.length][source2[0].length];
                    double [][] originalMwa = new double [source.length][source[0].length];
                    for (int i = 0; i < source2.length; i++) {
                        originalMwa[i] = MWA.normal(source[i], 5, 5);
                        mwa[i] = MWA.normal(source2[i], 5, 5);
                    }
                    originalMwa = bss.preWhiten(originalMwa);
                    originalMwa = bss.BSS(originalMwa, 50);
                    mwa = bss.preWhiten(mwa);
                    mwa = bss.BSS(mwa, 50);
                    results[k][teller] += euc.distance(originalMwa, mwa);
                    System.out.print(euc.distance(originalMwa, mwa)+ "\t");
                } else if(k==2) {
                    double [][] originalMwm = new double [source.length][source[0].length];
                    double [][] mwm = new double [source2.length][source2[0].length];
                    for (int i = 0; i < source2.length; i++) {
                        mwm[i] = MWA.median(source2[i], 5, 5);
                        originalMwm[i] = MWA.median(source[i], 5, 5);
                    }
                    originalMwm = bss.preWhiten(originalMwm);
                    originalMwm = bss.BSS(originalMwm, 50);
                    mwm = bss.preWhiten(mwm);
                    mwm = bss.BSS(mwm, 50);
                    results[k][teller] += euc.distance(originalMwm, mwm);
                    System.out.print(euc.distance(originalMwm, mwm) + "\t");
                } else if(k==3) {
                    double [][] originalMwg = new double [source.length][source[0].length];
                    double [][] mwg = new double [source2.length][source2[0].length];
                    for (int i = 0; i < source2.length; i++) {
                        mwg[i] = MWA.gaussian(source2[i], 5, 5);
                        originalMwg[i] = MWA.gaussian(source[i], 5, 5);
                    }
                    originalMwg = bss.preWhiten(originalMwg);
                    originalMwg = bss.BSS(originalMwg, 50);
                    mwg = bss.preWhiten(mwg);
                    mwg = bss.BSS(mwg, 50);
                    results[k][teller] += euc.distance(originalMwg, mwg);
                    System.out.print(euc.distance(originalMwg, mwg) + "\t");
                /*}else if(k == 4){
                    Kalman3 km = new Kalman3();
                    double [][] originalKalman = km.init(source, Buffer.getRecordDuration());
                    double [][] newKalman = km.init(source2, Buffer.getRecordDuration());
                    originalKalman = bss.preWhiten(originalKalman);
                    newKalman = bss.preWhiten(newKalman);
                    originalKalman = bss.BSS(originalKalman, 50);
                    newKalman = bss.BSS(newKalman, 50);
                    System.out.println(euc.distance(originalKalman, newKalman) + "\t");*/
                } else if(k==5) {
                    System.out.print(euc.distance(source2, source) + "\t");
                    results[k][teller] += euc.distance(source2, source);
                }
                teller++;
            }
        }
            for (int i = 0; i < results.length; i++) {
                System.out.println("\n k: " + i);
                for (int j = 0; j < results[0].length; j++) {
                    results[i][j]= results[i][j]/10;
                    System.out.print(results[i][j] + "\t");
                }
            }
        }
    }//GEN-LAST:event_jButton14ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            // Set System L&F
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            System.err.println("Fout bij toepassen L&F");
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                GUI gui = new GUI();
                gui.setVisible(true);
            }
        });
    }

    private void drawOriginalGraph(double[][] data) {
        Plot plot = new Plot();
        String[] dataLabel = {"Thorax 1", "Thorax 2", "Abdomen 1", "Abdomen 2", "Abdomen 3"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(data, "Original Data", dataLabel, "Sample", "Amplitude");
        panel.setPreferredSize(new Dimension(900, 400));
        chartPanel.add(panel);
        chartPanel.revalidate();
        chartPanel.repaint();
    }

    private void drawFourierGraph(double[][] data) {
        Fourier fourier = new Fourier();

        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        for (int i = 0; i < data.length; i++) {
            plotData[i] = fourier.forward(data[i]);
        }

        String[] dataLabel = {"Thorax 1", "Thorax 2", "Abdomen 1", "Abdomen 2", "Abdomen 3"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(plotData, "Fourier Transform", dataLabel, "Freq (Hz)", "Amplitude");
        fourierPanel.add(panel);
        fourierPanel.revalidate();
        fourierPanel.repaint();
    }

    private void drawHaarGraph(double[][] data) {
        HaarWavelet hw = new HaarWavelet();
        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        for (int i = 0; i < data.length; i++) {
            plotData[i] = hw.transform(data[i], null);
        }

        String[] dataLabel = {"Thorax 1", "Thorax 2", "Abdomen 1", "Abdomen 2", "Abdomen 3"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(plotData, "Haar Wavelet Transform", dataLabel, "", "");
        haarPanel.add(panel);
        haarPanel.revalidate();
        haarPanel.repaint();
    }

    private void drawKalmanGraph(double[][] data) {
        Kalman3 kalman = new Kalman3();

        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        plotData = kalman.init(data, Buffer.getRecordDuration());

        String[] dataLabel = {"Thorax 1", "Thorax 2", "Abdomen 1", "Abdomen 2", "Abdomen 3"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(plotData, "Adaptive Kalman Filter", dataLabel, "Sample", "mV");
        kalmanPanel.add(panel);
        kalmanPanel.revalidate();
        kalmanPanel.repaint();
    }

    private void drawDaubechiesGraph(double[][] data) {
        DaubechieWavelet daubechie = new DaubechieWavelet();

        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        for (int i = 0; i < data.length; i++) {
            plotData[i] = daubechie.daubechieTransform(data[i]);
        }

        String[] dataLabel = {"Thorax 1", "Thorax 2", "Abdomen 1", "Abdomen 2", "Abdomen 3"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(plotData, "Daubechies Wavelet Transform", dataLabel, "", "");
        daubechiesPanel.add(panel);
        daubechiesPanel.revalidate();
        daubechiesPanel.repaint();
    }

    private void drawBSSGraph(double[][] data) {
        BSS bss = new BSS();

        int res = JOptionPane.showConfirmDialog(rootPane, "Perform in Fourier domain?");
        if (res == JOptionPane.YES_OPTION) {
            Fourier fourier = new Fourier();
            for (int i = 0; i < data.length; i++) {
                data[i] = fourier.forward(data[i]);
            }
        }

        double[][] whiteData = bss.preWhiten(data);

        double[][] plotData = new double[data.length][Buffer.getCurrentSampleSize()];
        plotData = bss.BSS(whiteData, 50);

        if (res == JOptionPane.YES_OPTION) {
            Fourier fourier = new Fourier();
            for (int i = 0; i < data.length; i++) {
                plotData[i] = fourier.reverse(plotData[i]);
            }
        }

        String[] dataLabel = {"Signal 1", "Signal 2", "Signal 3", "Signal 4", "Signal 5"};
        ChartPanel panel = Plot.multipleChannelStandardPlot(plotData, "BSS", dataLabel, "Sample", "mV");
        bssPanel.add(panel);
        bssPanel.revalidate();
        bssPanel.repaint();
    }

    private double[][] getFilterData(int sampleSize) {
        Buffer.setCurrentSampleSize(sampleSize);
        int[] counter = new int[5];
        int counter2 = 0;
        if (jCheckBox1.isSelected()) {
            counter[0] = 1;
            counter2++;
        }
        if (jCheckBox2.isSelected()) {
            counter[1] = 1;
            counter2++;
        }
        if (jCheckBox3.isSelected()) {
            counter[2] = 1;
            counter2++;
        }
        if (jCheckBox4.isSelected()) {
            counter[3] = 1;
            counter2++;
        }
        if (jCheckBox5.isSelected()) {
            counter[4] = 1;
            counter2++;
        }

        double[][] data = new double[counter2][sampleSize];
        int counter3 = 0;
        for (int i = 0; i < 5; i++) {
            if (counter[i] == 1) {
                data[counter3] = Buffer.getSignalData(i);
                counter3++;
            }
        }
        return data;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel QRSBSSPanel;
    private javax.swing.JPanel bssPanel;
    private javax.swing.JPanel chartPanel;
    private javax.swing.JPanel daubechiesPanel;
    private javax.swing.JPanel fourierPanel;
    private javax.swing.JPanel haarPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel kalmanPanel;
    private javax.swing.JTextField sampleSizeField;
    private javax.swing.JPanel sineChartPanel;
    // End of variables declaration//GEN-END:variables
}
